//==============================================================================
// Copyright (c) 2008-2013 Niall Ryan. All Rights Reserved.
//==============================================================================

#ifndef HYDRA_ALLOCATORS_GARBAGECOLLECTIONALLOCATOR_H
#define HYDRA_ALLOCATORS_GARBAGECOLLECTIONALLOCATOR_H 1

#include <cstdlib>

namespace Hydra
{
    /**
     * An allocator which does not free any allocations - it assumes a garbage collector is active and will clean up all the allocations
     * it makes. It is therefore not vulnerable to the ABA problem.
     */
    class GarbageCollectionAllocator
    {
    public:
        static const bool kAbaVulnerable = false;
        static const bool kAllowsDanglingPointers = true;

		static void* alloc(size_t numBytes)
		{
			return ::malloc(numBytes);
		}

		template<typename T>
		static T* create()
		{
			T* item = static_cast<T*>(alloc(sizeof(T)));
			new(item) T;
			return item;
		}

		template<typename T>
		static T* createArray(size_t numElements)
		{
			T* arr = static_cast<T*>(alloc(sizeof(T)*numElements));
			for (unsigned int i=0; i<numElements; ++i)
				new(&arr[i]) T;
			return arr;
		}

		static void free(void* ptr)
		{
		}

		template<typename T>
		static void destroy(T* item)
		{
		}

		template<typename T>
		static void destroyArray(T* arr, size_t numElements)
		{
		}
    };
}

#endif
